package com.edu.juc.completableFuture.completionStage;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class APITest2 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService service = Executors.newFixedThreadPool(10);
        try {
            CompletableFuture.supplyAsync(() -> {
                System.out.println("1线程：" + Thread.currentThread().getName());
                return 1;
            }, service).thenRun(() -> {
                System.out.println("2线程：" + Thread.currentThread().getName());
            }).thenRun(() -> {
                System.out.println("3线程：" + Thread.currentThread().getName());
            }).thenRun(() -> {
                System.out.println("4线程：" + Thread.currentThread().getName());
            }).thenRunAsync(() -> {
                System.out.println("5线程：" + Thread.currentThread().getName());
            }).thenRunAsync(() -> {
                System.out.println("6线程：" + Thread.currentThread().getName());
            });
        } finally {
            TimeUnit.SECONDS.sleep(1);
            service.shutdown();
        }
    }
}
